/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.com.codefire.stream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

/**
 *
 * @author human
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        for (char i = 'a'; i < 97 + 26; i++) {
            baos.write(i);

            System.out.print(i + " ");
        }
        System.out.println();
        
        byte[] buffer = baos.toByteArray();
        
        String str = new String(buffer);
        System.out.println(str);
        
        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        
        byte [] buff = new byte[bais.available()];
        int bt, idx = 0;
        while ((bt = bais.read()) >= 0) {
            buff[idx++] = (byte) bt;
        }
    }
}
